Skip to content

Optimize applyFilter() to Avoid Redundant String Operations #11284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2021

Conversation

AdrianJBHughes
Copy link
Contributor

if 'showingHint' == true, then many potentially expensive String operations are being executed on an empty string. This change wraps these operations in an if block which will only run them when needed.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

if 'showingHint' == true, then many potentially expensive String operations are being executed on an empty string. This change wraps these operations in an if block which will only run them when needed.
@facchinm facchinm added this to the Release 1.8.14 milestone Mar 9, 2021
@cmaglie
Copy link
Member

cmaglie commented Apr 8, 2021

Hi @AdrianJBHughes

The change in this PR is not equivalent to the current version: if showingHint is false the onFilter(..) method must be called with an empty String[] array to reset the view but, in your version, is not called at all, this will leave the list of contributions "filtered" even if the user clears the text field.

// Replace anything but 0-9, a-z, or : with a space
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");

onFilter(filter.split(" "));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the other comment this method should be called with an empty array if showingHint is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note, I have addressed the above and pushed the changes.

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

@cmaglie cmaglie merged commit 3f0699a into arduino:master Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants